<template>
  <div class="wrap">
    <el-date-picker
      :editable="false"
      v-model="dateValue"
      type="date"
      value-format="yyyy-MM-dd"
      :picker-options="pickerOptions"
      placeholder="选择日期"
      @change="dateChange">
    </el-date-picker>
    <el-table
      class="table"
      border fit highlight-current-row
      v-loading="loading"
      element-loading-text="加载中"
      element-loading-spinner="el-icon-loading"
      :data="tableDataStatistic"
      style="width: 100%">
      <el-table-column
          align="center"
          prop="channelName"
          label="名称">
      </el-table-column>
     
      <el-table-column
          align="center"
          prop="registerNum"
          label="注册数">
      </el-table-column>
      <el-table-column
          align="center"
          prop="channelRealNum"
          label="实名数">
      </el-table-column>
      <el-table-column
          align="center"
          label="实名率">
          <template slot-scope="scope">
            <p>{{isNaN((scope.row.channelRealNum*100/scope.row.registerNum).toFixed(1)) ? '-' : ((scope.row.channelRealNum*100/scope.row.registerNum).toFixed(1))+'%'}}</p>
          </template>
      </el-table-column>
      <el-table-column
          align="center"
          prop="channelAppLoanNum"
          label="下款数">
      </el-table-column>
      <el-table-column
          align="center"
          label="下款率">
          <template slot-scope="scope">
            <p>{{isNaN((scope.row.channelAppLoanNum*100/scope.row.registerNum).toFixed(1)) ? '-' : ((scope.row.channelAppLoanNum*100/scope.row.registerNum).toFixed(1))+'%'}}</p>
          </template>
      </el-table-column>
    </el-table>
    <el-table
      class="table"
      border fit highlight-current-row
      v-loading="loading"
      element-loading-text="加载中"
      element-loading-spinner="el-icon-loading"
      :data="tableData"
      style="width: 100%">
      <el-table-column
          type="index"
          align="center"
          label="编号"
          width="50">
      </el-table-column>
      <el-table-column
          align="center"
          prop="phoneNum"
          label="手机号">
      </el-table-column>
      <el-table-column
          align="center"
          prop="ipAddress"
          label="用户ip地址">
      </el-table-column>
      <el-table-column
          align="center"
          label="注册时间">
          <template slot-scope="scope">
            {{_mapping.date_format(scope.row.createAt)}}
          </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="query.pageNum"
      :page-size="query.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum">
    </el-pagination>
  </div>
</template>
<script>
import _business from '@/services/business.js'
import _mapping from '@/utils/_mapping.js'
export default {
  data(){
    return {
      loading: false,
      tableData: [{
        number: 1,
        phoneNum: '13922325649',
        registerTime: '2019-05-22 11:12:11'
      }],
      tableDataStatistic: [],
      query: {
        pageSize: 30,
        pageNum: 1
      },
      totalNum: 0,
      dateValue: '',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val
      this.getUserList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val
      this.getUserList()
    },
    dateChange(val){
      console.log('datdateValuee', this.dateValue)
      this.getUserList()
      this.getStatistic()
    },
    getStatistic(){
      let params = {
        "searchDate": this.dateValue
       
      }
      _business.userstatistic(params)
      .then(res => {
        console.log('bussinessStatistic', res.data)
        this.tableDataStatistic = [{
         
          channelName: res.data.channelName || '',
          registerNum: res.data.registerNum || 0,
          channelRealNum: res.data.channelRealNum || 0,//实名数
          channelAppLoanNum: res.data.channelAppLoanNum || 0//下款数
        }]
      })
    },
    getUserList(){
      let params = {
        "pageNum": this.query.pageNum,
        "pageSize": this.query.pageSize,
        "searchDate": this.dateValue
      }
      _business.userList(params)
      .then(res => {
        console.log('bussinessList', res.data)
        this.tableData = res.data.list
        this.totalNum = res.data.total
      })
    }
  },
  created(){
    this.dateValue = this._mapping.date_format2(new Date())
    this.getStatistic()
    this.getUserList()
  }
}
</script>
<style lang="scss" scoped>
.wrap{
  .table{
    margin-top: 10px;
    margin-bottom: 25px;
  }
}
</style>